﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ModularFixture.CUiMFOriginParametersDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using C1.Win.C1FlexGrid;
using EngineeringInternalExtension;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui48;


namespace DnProcessSimulateCommands.ModularFixture;

public class CUiMFOriginParametersDlg : TxForm
{
  private const int MIN_COL = 1;
  private const int MAX_COL = 2;
  private const int X_ROW = 1;
  private const int Y_ROW = 2;
  private const int Z_ROW = 3;
  private CApMFConfigurationTypeData m_configData;
  private double m_value;
  private bool m_isValidFrame;
  private TxFrame m_frame;
  private IContainer components;
  private Label label1;
  private Label label2;
  private TxFlexGrid m_toleranceGrid;
  private TxFrameEditBoxCtrl m_fixtureUnitOrigin;
  private Button m_ok;
  private Button m_cancel;

  internal CUiMFOriginParametersDlg(CApMFConfigurationTypeData configData)
  {
    this.InitializeComponent();
    this.m_configData = configData;
    this.m_fixtureUnitOrigin.SetLocation(configData.FixtureUnitOrigin);
    this.m_isValidFrame = true;
  }

  internal void CreateFrameInGraphicViewer(TxTransformation transformation)
  {
    this.DeleteFrame();
    this.m_frame = TxFrameEx.CreateFrame(new TxFrameCreationDataEx("workingFrameTemp", transformation, true));
    TxApplication.RefreshDisplay();
  }

  internal void DeleteFrame()
  {
    if (!TxFrame.op_Inequality(this.m_frame, (ITxObject) null))
      return;
    this.m_frame.Delete();
    this.m_frame = (TxFrame) null;
    TxApplication.RefreshDisplay();
  }

  private void CUiMFOriginParametersDlg_Load(object sender, EventArgs e)
  {
    this.m_fixtureUnitOrigin.ListenToPick = true;
    this.m_fixtureUnitOrigin.Focus();
    ((C1FlexGridBase) this.m_toleranceGrid).SetData(1, 0, (object) "X");
    ((C1FlexGridBase) this.m_toleranceGrid).SetData(2, 0, (object) "Y");
    ((C1FlexGridBase) this.m_toleranceGrid).SetData(3, 0, (object) "Z");
    ((C1FlexGridBase) this.m_toleranceGrid).SetData(1, 1, (object) this.m_configData.MinToleranceX);
    ((C1FlexGridBase) this.m_toleranceGrid).SetData(2, 1, (object) this.m_configData.MinToleranceY);
    ((C1FlexGridBase) this.m_toleranceGrid).SetData(3, 1, (object) this.m_configData.MinToleranceZ);
    ((C1FlexGridBase) this.m_toleranceGrid).SetData(1, 2, (object) this.m_configData.MaxToleranceX);
    ((C1FlexGridBase) this.m_toleranceGrid).SetData(2, 2, (object) this.m_configData.MaxToleranceY);
    ((C1FlexGridBase) this.m_toleranceGrid).SetData(3, 2, (object) this.m_configData.MaxToleranceZ);
  }

  private void CUiMFOriginParametersDlg_FormClosed(object sender, FormClosedEventArgs e)
  {
    this.DeleteFrame();
  }

  private void m_ok_Click(object sender, EventArgs e)
  {
    if (this.m_isValidFrame)
      this.m_configData.FixtureUnitOrigin = this.m_fixtureUnitOrigin.GetLocation();
    this.m_configData.FixtureUnitOriginSet = true;
    this.m_configData.SetToleranceParams((double) ((C1FlexGridBase) this.m_toleranceGrid).GetData(1, 1), (double) ((C1FlexGridBase) this.m_toleranceGrid).GetData(1, 2), (double) ((C1FlexGridBase) this.m_toleranceGrid).GetData(2, 1), (double) ((C1FlexGridBase) this.m_toleranceGrid).GetData(2, 2), (double) ((C1FlexGridBase) this.m_toleranceGrid).GetData(3, 1), (double) ((C1FlexGridBase) this.m_toleranceGrid).GetData(3, 2));
    ((Form) this).Close();
  }

  private void m_cancel_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void m_toleranceGrid_AfterEdit(object sender, RowColEventArgs e)
  {
    if (((C1FlexGridBase) this.m_toleranceGrid).GetData(e.Row, e.Col) == null)
    {
      ((C1FlexGridBase) this.m_toleranceGrid).SetData(e.Row, e.Col, (object) this.m_value);
    }
    else
    {
      if ((double) ((C1FlexGridBase) this.m_toleranceGrid).GetData(e.Row, 1) <= (double) ((C1FlexGridBase) this.m_toleranceGrid).GetData(e.Row, 2))
        return;
      ((C1FlexGridBase) this.m_toleranceGrid).SetData(e.Row, e.Col, (object) this.m_value);
      int num = (int) TxMessageBox.Show(CApMFAdminUtils.m_resourceManager.GetString("MIN_MAX_ERROR_MESSAGE"), CApMFAdminUtils.m_resourceManager.GetString("CMD_CONFIGURATION_ADMINISTRATOR_NAME"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
  }

  private void m_toleranceGrid_BeforeEdit(object sender, RowColEventArgs e)
  {
    if (e.Row <= 0 || e.Col <= 0)
      return;
    this.m_value = (double) ((C1FlexGridBase) this.m_toleranceGrid).GetData(e.Row, e.Col);
  }

  private void m_fixtureUnitOrigin_InvalidFrameSet(
    object sender,
    TxFrameEditBoxCtrl_InvalidFrameSetEventArgs args)
  {
    this.m_isValidFrame = false;
    this.DeleteFrame();
  }

  private void m_fixtureUnitOrigin_ValidFrameSet(
    object sender,
    TxFrameEditBoxCtrl_ValidFrameSetEventArgs args)
  {
    this.m_isValidFrame = true;
    this.CreateFrameInGraphicViewer(this.m_fixtureUnitOrigin.GetLocation());
  }

  internal CApMFConfigurationTypeData ConfigurationData => this.m_configData;

  internal TxTransformation FixtureUnitOrigin => this.m_fixtureUnitOrigin.GetLocation();

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiMFOriginParametersDlg));
    this.label1 = new Label();
    this.label2 = new Label();
    this.m_toleranceGrid = new TxFlexGrid();
    this.m_fixtureUnitOrigin = new TxFrameEditBoxCtrl();
    this.m_ok = new Button();
    this.m_cancel = new Button();
    ((ISupportInitialize) this.m_toleranceGrid).BeginInit();
    ((Control) this).SuspendLayout();
    this.label1.AutoSize = true;
    this.label1.Location = new Point(9, 16 /*0x10*/);
    this.label1.Name = "label1";
    this.label1.Size = new Size(93, 13);
    this.label1.TabIndex = 0;
    this.label1.Text = "Fixture Unit Origin:";
    this.label2.AutoSize = true;
    this.label2.Location = new Point(10, 75);
    this.label2.Name = "label2";
    this.label2.Size = new Size(159, 13);
    this.label2.TabIndex = 1;
    this.label2.Text = "Allowable Placement Tolerance:";
    ((C1FlexGridBase) this.m_toleranceGrid).ColumnInfo = componentResourceManager.GetString("m_toleranceGrid.ColumnInfo");
    ((Control) this.m_toleranceGrid).Location = new Point(12, 93);
    ((Control) this.m_toleranceGrid).Name = "m_toleranceGrid";
    ((RowColCollection) ((C1FlexGridBase) this.m_toleranceGrid).Rows).Count = 4;
    ((C1FlexGridBase) this.m_toleranceGrid).SelectionMode = (SelectionModeEnum) 1;
    ((Control) this.m_toleranceGrid).Size = new Size(220, 72);
    ((Control) this.m_toleranceGrid).TabIndex = 3;
    ((C1FlexGridBase) this.m_toleranceGrid).AfterEdit += new RowColEventHandler(this.m_toleranceGrid_AfterEdit);
    ((C1FlexGridBase) this.m_toleranceGrid).BeforeEdit += new RowColEventHandler(this.m_toleranceGrid_BeforeEdit);
    this.m_fixtureUnitOrigin.EnableRelativeToWorkingFrameCoordinates = true;
    this.m_fixtureUnitOrigin.ListenToPick = false;
    ((Control) this.m_fixtureUnitOrigin).Location = new Point(12, 34);
    ((Control) this.m_fixtureUnitOrigin).Name = "m_fixtureUnitOrigin";
    ((Control) this.m_fixtureUnitOrigin).Size = new Size(221, 25);
    ((Control) this.m_fixtureUnitOrigin).TabIndex = 4;
    this.m_fixtureUnitOrigin.ValidFrameSet += new TxFrameEditBoxCtrl_ValidFrameSetEventHandler(this.m_fixtureUnitOrigin_ValidFrameSet);
    this.m_fixtureUnitOrigin.InvalidFrameSet += new TxFrameEditBoxCtrl_InvalidFrameSetEventHandler(this.m_fixtureUnitOrigin_InvalidFrameSet);
    this.m_ok.DialogResult = DialogResult.OK;
    this.m_ok.Location = new Point(49, 188);
    this.m_ok.Name = "m_ok";
    this.m_ok.Size = new Size(75, 23);
    this.m_ok.TabIndex = 5;
    this.m_ok.Text = "OK";
    this.m_ok.UseVisualStyleBackColor = true;
    this.m_ok.Click += new EventHandler(this.m_ok_Click);
    this.m_cancel.DialogResult = DialogResult.Cancel;
    this.m_cancel.Location = new Point(130, 188);
    this.m_cancel.Name = "m_cancel";
    this.m_cancel.Size = new Size(75, 23);
    this.m_cancel.TabIndex = 6;
    this.m_cancel.Text = "Cancel";
    this.m_cancel.UseVisualStyleBackColor = true;
    this.m_cancel.Click += new EventHandler(this.m_cancel_Click);
    ((ContainerControl) this).AutoScaleDimensions = new SizeF(6f, 13f);
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).ClientSize = new Size(242, 219);
    ((Control) this).Controls.Add((Control) this.m_cancel);
    ((Control) this).Controls.Add((Control) this.m_ok);
    ((Control) this).Controls.Add((Control) this.m_fixtureUnitOrigin);
    ((Control) this).Controls.Add((Control) this.m_toleranceGrid);
    ((Control) this).Controls.Add((Control) this.label2);
    ((Control) this).Controls.Add((Control) this.label1);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).Icon = (Icon) componentResourceManager.GetObject("$this.Icon");
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiMFOriginParametersDlg);
    ((Control) this).Text = "Set Origin Parameters";
    ((Form) this).ShowIcon = false;
    ((Form) this).Load += new EventHandler(this.CUiMFOriginParametersDlg_Load);
    ((Form) this).FormClosed += new FormClosedEventHandler(this.CUiMFOriginParametersDlg_FormClosed);
    ((ISupportInitialize) this.m_toleranceGrid).EndInit();
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }
}
